import { defineStore } from 'pinia'
import { ref } from 'vue'

// 金泰EAM存储数据
export const useWmsStore = defineStore("wms", () => {
	// state
	// 设备选择数据
	const deviceList = ref(uni.getStorageSync("deviceList") || '[]')
	// feeder 料架
	const feederList = ref(uni.getStorageSync("feederList") || '[]')
	// bin 仓位
	const binList = ref(uni.getStorageSync("binList") || '[]')
	// orgin 库存转移目标源
	const orginList = ref(uni.getStorageSync("orginList") || '[]')
	// action
	/**
	 * 设置设备选择数据
	 */
	function setDeviceList(data='') {
		deviceList.value = data?JSON.stringify([data]):'[]'
		uni.setStorageSync("deviceList", deviceList.value)
	}
	/**
	 * 设置 feederList
	 */
	function setFeederList(data : any) {
		feederList.value = JSON.stringify(data)
		uni.setStorageSync("feederList", feederList.value)
	}
	/**
	 * 设置 binList
	 */
	function setBinList(data : any) {
		binList.value = JSON.stringify(data)
		uni.setStorageSync("binList", binList.value)
	}
	/**
	 * 设置 orginList
	 */
	function setOrginList(data : any) {
		orginList.value = JSON.stringify(data)
		uni.setStorageSync("orginList", orginList.value)
	}
	
	return {
		deviceList,
		setDeviceList,
		binList,
		setBinList,
		feederList,
		setFeederList,
		orginList,
		setOrginList
	}
})